/**
 * 公共方法
 **/
var Publicethod = {}

//组织结构节点扁平数组转树状数组
Publicethod.arrayOrganizationalStructure = function(froum){
    for (let i in froum) {
        froum[i].value = froum[i].os_id;
        froum[i].label = froum[i].os_name;
    }
    let temp = {};
    let ans = [];
    for (let i in froum) {
        temp[froum[i].value] = froum[i];

    }
    for (let i in temp) {
        if (temp[i].os_fid != 0) {
            if (!temp[temp[i].os_fid].children) {
                temp[temp[i].os_fid].children = [];

            }
            temp[temp[i].os_fid].children.push(temp[i]);
        } else {
            ans.push(temp[i]);

        }
    }
    return ans;
}

//左侧菜单栏扁平数组转树状数组
Publicethod.arrayReorganization = function(froum){
    for (let i in froum) {
        froum[i].value = froum[i].m_id;
        froum[i].label = froum[i].m_name;
        froum[i].valueLabel = froum[i].m_id + ',' + froum[i].m_url;
    }
    let temp = {};
    let ans = [];
    for (let i in froum) {
        temp[froum[i].value] = froum[i];

    }
    for (let i in temp) {
        if (temp[i].m_fid != 0) {
            if (!temp[temp[i].m_fid].children) {
                temp[temp[i].m_fid].children = [];

            }
            temp[temp[i].m_fid].children.push(temp[i]);
        } else {
            ans.push(temp[i]);

        }
    }
    return ans;
}

//新建文件及文件夹
Publicethod.newlyBuild = function(params,temporaryFatherData){

    var type = ''

    var m_path = params.m_path.split(",")

    m_path.splice(0, 1);

    m_path.splice(m_path.length-1, 1);

    var string = []

    if(m_path.length > 0){

        for (var i = 0; i < temporaryFatherData.length; i++) {

            if (temporaryFatherData[i].m_id == m_path[0]) {

                string.push(temporaryFatherData[i].m_url)

            }

            if (temporaryFatherData[i].children && temporaryFatherData[i].children.length > 0) {

                for (var v = 0; v < temporaryFatherData[i].children.length; v++) {

                    if (temporaryFatherData[i].children[v].m_id == m_path[1]) {

                        string.push(temporaryFatherData[i].children[v].m_url)

                    }

                    if (temporaryFatherData[i].children[v].children && temporaryFatherData[i].children[v].children.length > 0) {

                        for (var n = 0; n < temporaryFatherData[i].children[v].children.length; n++) {

                            if (temporaryFatherData[i].children[v].children[n].m_id == m_path[2]) {

                                string.push(temporaryFatherData[i].children[v].children[n].m_url)

                            }
                        }

                    }
                }

            }

        }

    }

    if(params.m_type == 0){

        type = './client/views/systemView/'

    }else if(params.m_type == 1){

        type = './client/views/extensionView/'

    }else if(params.m_type == 2){

        type = './client/views/bussinessView/'

    }
    

    if(string.length>0){

        type +=  string.join('/') + "/"

    }

    if(params.m_level == 0){

        type = type + params.m_url

    }else if(params.m_level == 1){

        type = type + params.m_url

    }else if(params.m_level == 2){

        type = type + params.m_url + "/" + params.m_url + ".vue"

    }else if(params.m_level == 3){

        type = type + params.m_url + "/" + params.m_url + ".vue"

    }

    return type;
}

//获取当前事件
Publicethod.currentTime = function(params){

    var timestamp = Date.parse(new Date()) / 1000;

    return timestamp
}

//验证电话
Publicethod.vPhone = function(str) {
    var reg = /^1[3|4|5|7|8][0-9]{9}$/;
    return reg.test(str);
}

//去除字符串最后一位
Publicethod.deleteLastStr = function(str) {
    return str.substr(0, str.length - 1)
}

export default Publicethod
